app.controller('applyOffLease', function($element, ngDialog ,$scope, $state, rest, user,uploadConf,tipService,uiLoad,$localStorage) {
    var data = angular.copy($scope.ngDialogData, {});
    $scope.params = {
      initiatorOpenId: user.get('openId')
    };

    console.log($scope.params.initiatorOpenId);
    $scope.$on('rentTime.start', function(event, data) {
        $scope.params.exitDate = data + " 00:00:00";
    })

    $scope.params.contractId = data.contractId;
    $scope.params.statusName = data.status;
    $scope.now = function(){
      var d = new Date();
      var year = d.getFullYear();
      var month = d.getMonth() + 1;
      var dt = d.getDate();
      if (month<10) {
        if (dt<10) {
          $scope.today = year + "/" + "0"+month + "/" + "0"+dt + " 00:00:00";
        }else{
          $scope.today = year + "/" + "0"+month + "/" + dt + " 00:00:00";
        }
      }else{
        if (dt<10) {
          $scope.today = year + "/" + month + "/" + "0"+dt + " 00:00:00";
        }else{
          $scope.today = year + "/" + month + "/" + dt + " 00:00:00";
        }
      }

    }
    //点击确定按钮
    $scope.modifySure = function() {
      console.log(data);
      $scope.now();
      console.log($scope.today);
      console.log($scope.params.exitDate);
      if ($scope.params.exitDate <= $scope.today) {
        tipService.show("body", {
            message: "退租日期为次日起至租约到期日",
            notice:"danger"
        }, 3);
        return;
      }

      $scope.closeThisDialog({clickOk: true});
      rest.post({
          methodId: '1050',
          data: $scope.params,
          success: function(res) {
              if (res.code == 0) {
                  tipService.show("body", {
                      message: "退租申请成功,跳转中......"
                  }, 3);
              } else {
                  tipService.show("body", {
                      message: res.res.msg,
                      notice: "danger"
                  }, 3);
              }
          },
          error: function() {
              btn.removeClass('disabled');
          }
      })
    }

});

app.controller('TimeCtrl', function($scope) {

    $scope.today = function() {
        $scope.LeaseStartTime = moment().format('YYYY/MM/DD');
    };
    $scope.closeAll = function() {
        $scope.openLeaseBeginDated = false;
    }

    $scope.openLeaseBeginDate = function($event) {
        $event.preventDefault();
        $event.stopPropagation();
        $scope.closeAll();
        $scope.openLeaseBeginDated = true;
    };

    $scope.dateOptions = {
        format: 'yyyy/MM/dd',
        startingDay: 1,
        class: 'datepicker'
    };

    $scope.format = 'yyyy/MM/dd';
    $scope.today();
    
    $scope.$watch('LeaseStartTime', function(newValue, oldValue) {
        if ("[object Date]" === Object.prototype.toString.call(newValue)) {
            $scope.$emit('rentTime.start', moment(newValue).format('YYYY/MM/DD'))
        }
    });

});